<?php
namespace app\admin\controller;
use think\Controller;

class Member extends Base
{
	//会员列表
	public function memList()
	{
		$a=model('Member');
		$res=$a->show()->paginate([
			'list_rows'=>5,
			'query'=>input('get.'),
			'var_page'=>'p'
		]);
		$cou=model('Member')->cou();
		$this->assign('res',$res);
		$this->assign('cou',$cou);
		return $this->fetch();
	}
	//会员列表添加
	public function memListAdd()
	{
		//dump(input());
		if($this->request->isPost())
		{
			$result=$this->validate(input(),'Member');
			if($result===true)
			{
				$time=time();
				$arr=[
					'username'=>input('post.username'),
					'name'=>input('post.name'),
					'password'=>input('post.pwd'),
					'phone'=>input('post.phone'),
					'email'=>input('post.email'),
					'time'=>$time,
				];
				model('member')->addm($arr);
				return $this->success('添加成功');
			}
			else
			{
				return $this->error($result);
			}
		}
		else
		{
			return $this->fetch();
		}
	}
	//会员列表修改
	public function memListEdit()
	{
		//dump(input('param.id'));
		
		if($this->request->isPost())
		{
			//dump(input());
			$result=$this->validate(input(),'Member');
			if($result===true)
			{
				$time=time();
				$id=input('post.id');
				$arr=[
					'username'=>input('post.username'),
					'name'=>input('post.name'),
					'password'=>input('post.pwd'),
					'phone'=>input('post.phone'),
					'email'=>input('post.email'),
					'time'=>$time,
				];
				model('Member')->updm($id,$arr);
				return $this->success('修改成功');
			}
			else
			{
				return $this->error($result);
			}
		}
		else
		{
			$res=model('Member')->selm(input('param.id'));
			$this->assign('res',$res);
			return $this->fetch();
		}
	}
	//会员列表删除
	public function memListDel()
	{
		$id=input('post.id');
		if(input('post.allid'))
		{
			$id=substr(input('post.allid'),0,-1);
		}
		//dump($id);
		$result=model('Member')->delm($id);
		if($result===0)
		{
			return $this->error('删除失败');
		}
		else
		{
			return $this->success('删除成功');
		}
	}

	//会员砍价
	public function bargain()
	{
		return $this->fetch();
	}
	//会员预约
	public function order()
	{
		return $this->fetch();
	}

	//评估管理
	public function evaluate()
	{
		$a=model('Evaluate');
		$res=$a->show()->paginate([
			'list_rows'=>5,
			'query'=>input('get.'),
			'var_page'=>'p'
		]);
		//dump($res);
		$this->assign('res',$res);
		$total=model('Evaluate')->tot();
		$this->assign('total',$total);

		if(input('get.uid')!=null)
		{
			model('Evaluate')->updo(input('get.uid'),1);
		}
		if(input('get.oid')!=null)
		{
			model('Evaluate')->updo(input('get.oid'),2);
		}
		return $this->fetch();
	}
	//评估删除
	public function evaluatedel()
	{
		$id=input('post.id');
		if(input('post.allid'))
		{
			$id=substr(input('post.allid'),0,-1);
		}
		//dump($id);
		$result=model('Evaluate')->del($id);
		if($result===0)
		{
			return $this->error('删除失败');
		}
		else
		{
			return $this->success('删除成功');
		}
	}
}